<!-- @format -->

<template>
    <div ref="chart"></div>
</template>

<script>
import mixin from '../../../packages/src/util/mixin'
import CONFIG from '../../../packages/src/config/config_'
import _merge from 'lodash/merge'
import { AXIS_STYLE, LEGEND } from '../../../packages/src/util/nomalChart'
import util from '../../../packages/src/util/util'
export default {
    name: 'ZChart',
    mixins: [mixin],
    methods: {
        initChart() {
            let option = util.deepClone(this.option)
            if (option.legend) {
                option.legend = _merge(LEGEND(), option.legend)
            }

            option.color = option.color || CONFIG.COLOR
            option.textStyle = {
                color: CONFIG.FONT_COLOR,
                fontSize: CONFIG.FONT_S,
            }

            //当配置项有坐标轴时， 取坐标轴的统一样式， 并使统一样式优先级低于设置样式
            let xAxis = option.xAxis
            if (option.xAxis) {
                if (xAxis.constructor === Array) {
                    xAxis.forEach((v, i) => {
                        xAxis[i] = _merge({}, AXIS_STYLE(), v)
                    })
                } else {
                    xAxis = _merge(AXIS_STYLE(), xAxis)
                }
            }
            option.xAxis = xAxis
            let yAxis = option.yAxis
            if (option.yAxis) {
                if (yAxis.constructor === Array) {
                    yAxis.forEach((v, i) => {
                        yAxis[i] = _merge({}, AXIS_STYLE(), v)
                    })
                } else {
                    yAxis = _merge({}, AXIS_STYLE(), yAxis)
                }
            }
            option.yAxis = yAxis

            if (option.series) {
                option.series.forEach((v) => {
                    if (v.type === 'bar' && !v.barWidth && !v.barMaxWidth) {
                        v.barMaxWidth = 20
                    }
                })
            }
            return option
        },
    },
}
</script>

<style scoped></style>
